#include <assert.h>
#include "interface.h"

GtkWidget*
create_windowMonitorPopup (char *time, char *name, char *text)
{
  GtkWidget *windowMonitorPopup;
  GdkPixbuf *windowMonitorPopup_icon_pixbuf;
  GtkWidget *vboxAlert;
  GtkWidget *hboxPopup;
  GtkWidget *vboxWarningPic;
  GtkWidget *imageWarning;
  GtkWidget *vboxData;
  GtkWidget *tableMetaData;
  GtkWidget *labelTime;
  GtkWidget *labelMonitor;
  GtkWidget *labelTimeData;
  GtkWidget *labelMonitorName;
  GtkWidget *scrolledwindowMessage;
  GtkWidget *textviewMessage;
  GtkWidget *hbuttonboxOK;
  GtkWidget *buttonOK;
  GtkTooltips *tooltips;

  tooltips = gtk_tooltips_new ();
  
  assert(time != NULL);
  assert(name != NULL);
  assert(text != NULL);

  windowMonitorPopup = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_usize (windowMonitorPopup, 475, -2);
  gtk_container_set_border_width (GTK_CONTAINER (windowMonitorPopup), 2);
  gtk_tooltips_set_tip (tooltips, windowMonitorPopup, _("w3live Alert!"), NULL);
  gtk_window_set_title (GTK_WINDOW (windowMonitorPopup), _("w3live - Alert"));
  gtk_window_set_position (GTK_WINDOW (windowMonitorPopup), GTK_WIN_POS_MOUSE);
  gtk_window_set_resizable (GTK_WINDOW (windowMonitorPopup), FALSE);
  gtk_window_set_destroy_with_parent (GTK_WINDOW (windowMonitorPopup), TRUE);
  windowMonitorPopup_icon_pixbuf = create_pixbuf ("w3live/w3live.xpm");
  if (windowMonitorPopup_icon_pixbuf)
    {
      gtk_window_set_icon (GTK_WINDOW (windowMonitorPopup), windowMonitorPopup_icon_pixbuf);
      gdk_pixbuf_unref (windowMonitorPopup_icon_pixbuf);
    }

  vboxAlert = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (vboxAlert);
  gtk_container_add (GTK_CONTAINER (windowMonitorPopup), vboxAlert);

  hboxPopup = gtk_hbox_new (FALSE, 10);
  gtk_widget_show (hboxPopup);
  gtk_box_pack_start (GTK_BOX (vboxAlert), hboxPopup, TRUE, TRUE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (hboxPopup), 5);

  vboxWarningPic = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (vboxWarningPic);
  gtk_box_pack_start (GTK_BOX (hboxPopup), vboxWarningPic, FALSE, FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (vboxWarningPic), 10);

  imageWarning = gtk_image_new_from_stock ("gtk-dialog-warning", GTK_ICON_SIZE_DIALOG);
  gtk_widget_show (imageWarning);
  gtk_box_pack_start (GTK_BOX (vboxWarningPic), imageWarning, FALSE, FALSE, 0);

  vboxData = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (vboxData);
  gtk_box_pack_start (GTK_BOX (hboxPopup), vboxData, TRUE, TRUE, 0);

  tableMetaData = gtk_table_new (2, 2, FALSE);
  gtk_widget_show (tableMetaData);
  gtk_box_pack_start (GTK_BOX (vboxData), tableMetaData, FALSE, FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (tableMetaData), 10);
  gtk_table_set_row_spacings (GTK_TABLE (tableMetaData), 5);
  gtk_table_set_col_spacings (GTK_TABLE (tableMetaData), 5);

  labelTime = gtk_label_new (_("<i>Time:</i>"));
  gtk_widget_show (labelTime);
  gtk_table_attach (GTK_TABLE (tableMetaData), labelTime, 0, 1, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_label_set_use_markup (GTK_LABEL (labelTime), TRUE);
  gtk_label_set_justify (GTK_LABEL (labelTime), GTK_JUSTIFY_LEFT);
  gtk_misc_set_alignment (GTK_MISC (labelTime), 0, 0.5);

  labelMonitor = gtk_label_new (_("<i>Monitor:</i>"));
  gtk_widget_show (labelMonitor);
  gtk_table_attach (GTK_TABLE (tableMetaData), labelMonitor, 0, 1, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_label_set_use_markup (GTK_LABEL (labelMonitor), TRUE);
  gtk_label_set_justify (GTK_LABEL (labelMonitor), GTK_JUSTIFY_LEFT);
  gtk_misc_set_alignment (GTK_MISC (labelMonitor), 0, 0.5);

  labelTimeData = gtk_label_new ((gchar *)time);
  gtk_widget_show (labelTimeData);
  gtk_table_attach (GTK_TABLE (tableMetaData), labelTimeData, 1, 2, 0, 1,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_label_set_justify (GTK_LABEL (labelTimeData), GTK_JUSTIFY_LEFT);
  gtk_misc_set_alignment (GTK_MISC (labelTimeData), 0, 0.5);

  labelMonitorName = gtk_label_new ((gchar *)name);
  gtk_widget_show (labelMonitorName);
  gtk_table_attach (GTK_TABLE (tableMetaData), labelMonitorName, 1, 2, 1, 2,
                    (GtkAttachOptions) (GTK_FILL),
                    (GtkAttachOptions) (0), 0, 0);
  gtk_label_set_justify (GTK_LABEL (labelMonitorName), GTK_JUSTIFY_LEFT);
  gtk_misc_set_alignment (GTK_MISC (labelMonitorName), 0, 0.5);

  scrolledwindowMessage = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_show (scrolledwindowMessage);
  gtk_box_pack_start (GTK_BOX (vboxData), scrolledwindowMessage, FALSE, FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (scrolledwindowMessage), 10);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindowMessage), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

  textviewMessage = gtk_text_view_new ();
  gtk_widget_show (textviewMessage);
  gtk_container_add (GTK_CONTAINER (scrolledwindowMessage), textviewMessage);
  gtk_widget_set_usize (textviewMessage, -2, 100);
  gtk_text_view_set_editable (GTK_TEXT_VIEW (textviewMessage), FALSE);
  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textviewMessage), GTK_WRAP_WORD);
  gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (textviewMessage), FALSE);
  gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (textviewMessage), 5);
  gtk_text_view_set_pixels_below_lines (GTK_TEXT_VIEW (textviewMessage), 5);
  gtk_text_view_set_left_margin (GTK_TEXT_VIEW (textviewMessage), 5);
  gtk_text_view_set_right_margin (GTK_TEXT_VIEW (textviewMessage), 5);
  gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (textviewMessage)),(gchar *)text, -1);

  hbuttonboxOK = gtk_hbutton_box_new ();
  gtk_widget_show (hbuttonboxOK);
  gtk_box_pack_start (GTK_BOX (vboxAlert), hbuttonboxOK, TRUE, TRUE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (hbuttonboxOK), 5);
  gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonboxOK), GTK_BUTTONBOX_END);
  gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonboxOK), 5);

  buttonOK = gtk_button_new_from_stock ("gtk-ok");
  gtk_widget_show (buttonOK);
  gtk_container_add (GTK_CONTAINER (hbuttonboxOK), buttonOK);
  GTK_WIDGET_SET_FLAGS (buttonOK, GTK_CAN_DEFAULT);
  
  gtk_signal_connect(GTK_OBJECT(buttonOK),"clicked",
		  GTK_SIGNAL_FUNC(PopupClose),
		  GTK_OBJECT(windowMonitorPopup));

  /* Store pointers to all widgets, for use by lookup_widget(). */
  GLADE_HOOKUP_OBJECT_NO_REF (windowMonitorPopup, windowMonitorPopup, "windowMonitorPopup");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, vboxAlert, "vboxAlert");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, hboxPopup, "hboxPopup");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, vboxWarningPic, "vboxWarningPic");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, imageWarning, "imageWarning");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, vboxData, "vboxData");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, tableMetaData, "tableMetaData");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, labelTime, "labelTime");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, labelMonitor, "labelMonitor");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, labelTimeData, "labelTimeData");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, labelMonitorName, "labelMonitorName");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, scrolledwindowMessage, "scrolledwindowMessage");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, textviewMessage, "textviewMessage");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, hbuttonboxOK, "hbuttonboxOK");
  GLADE_HOOKUP_OBJECT (windowMonitorPopup, buttonOK, "buttonOK");
  GLADE_HOOKUP_OBJECT_NO_REF (windowMonitorPopup, tooltips, "tooltips");

  return windowMonitorPopup;
}

void
PopupClose                             (GtkButton       *button,
                                        gpointer         user_data)
{
	gtk_widget_destroy((GtkWidget *)user_data);
}
